package com.flying.ouyu.config;

import com.flying.ouyu.OuyuApplication;

import android.content.Context;
import android.content.SharedPreferences;

public class Config {
	
	private static Object instanceLocker = new Object();
	private static Config _instance = null;
	
	public static Config getInstance()
	{
		if (_instance != null)
			return _instance;
		
		synchronized(instanceLocker)
		{
			if (_instance == null)
			{
				_instance = new Config();
			}
			
			return _instance;
		}
	}
	
	private SharedPreferences sharedPref = null;
	private Config(){
		
		sharedPref = getPref();
	}
	
	private SharedPreferences getPref(){
		return OuyuApplication.getInstance().getSharedPreferences("protocol", 
				Context.MODE_PRIVATE);
	}
	
	private String getString(String key,String defValue)
	{
		return sharedPref.getString(key, defValue);
	}
	
	private int getInt(String key,int defValue)
	{
		return sharedPref.getInt(key, defValue);
	}
	
	private long getLong(String key,Long defValue)
	{
		return sharedPref.getLong(key, defValue);
	}
	
	private boolean getBoolean(String key,boolean defValue)
	{
		return sharedPref.getBoolean(key, defValue);
	}
	
	private float getFloat(String key,float defValue)
	{
		return sharedPref.getFloat(key, defValue);
	}
	
	private void putString(String key,String value)
	{
		sharedPref.edit().putString(key, value);
		sharedPref.edit().commit();
	}
	
	private void putInt(String key,int value)
	{
		sharedPref.edit().putInt(key, value);
		sharedPref.edit().commit();
	}
	
	private void putLong(String key,long value)
	{
		sharedPref.edit().putLong(key, value);
		sharedPref.edit().commit();
	}
	
	private void putBoolean(String key,boolean value)
	{
		sharedPref.edit().putBoolean(key, value);
		sharedPref.edit().commit();
	}
	
	private void putFloat(String key,float value)
	{
		sharedPref.edit().putFloat(key, value);
		sharedPref.edit().commit();
	}
	
	
	private static final String SessionKey = "sessionkey";
	public String getSessionKey()
	{
		return getString(SessionKey,null);
	}
	public void setSesssionKey(String value)
	{
		putString(SessionKey,value);
	}
	
	private static final String LoginNameKey = "loginName";
	public String getLoginName()
	{
		return getString(LoginNameKey,null);
	}
	public void setLoginName(String value)
	{
		putString(LoginNameKey,value);
	}
	
}
